﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;

public partial class User_Admin_RegisterVillage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LblStatus.Text = "";
        if (!Page.IsPostBack)
        {
            DropDownListCity.DataSource = DataAccess.TblCity.FetchAll();
            DropDownListCity.DataValueField = "ID";
            DropDownListCity.DataTextField = "Name";
            DropDownListCity.DataBind();
        }
       
    }
    protected void BtnRegister_Click(object sender, EventArgs e)
    {
        try
        {
            TblVillage v = new DataAccess.TblVillage();
            //v.BakhshId =new Guid( DrpBakhsh.SelectedItem.Value);
            Guid dehestanid =new Guid( DropDownListDehestan.SelectedItem.Value);
            v.DehstanId = dehestanid;
            v.Khanevar = Convert.ToInt32(TxtKhanevar.Text);
            v.Name = TxtVillageName.Text;
            v.Population = Convert.ToInt32(TxtPopulation.Text);
            v.VillageCode = TxtVillageCode.Text;
            v.Save();
            if (v.HasErrors() == false)
            {
                LblStatus.Text = " <script>alert('.ثبت روستا با موفقیت انجام شد')</script>";
            }
            else
            {
                LblStatus.Text = " <script>alert('.ثبت با خطا مواجه شد')</script>";
            }
        }
        catch
        {
            LblStatus.Text = " <script>alert('.ثبت با خطا مواجه شد')</script>";
        }
    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        
     
        TxtKhanevar.Text = "";
        TxtPopulation.Text = "";
      
        TxtVillageCode.Text = "";
        TxtVillageName.Text = "";
    }
    protected void DropDownListCity_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownListBakhsh.DataSource = DataAccess.TblBakhsh.FetchByParameter(DataAccess.TblBakhsh.Columns.CityId, SubSonic.Comparison.Equals, DropDownListCity.SelectedItem.Value);
        DropDownListBakhsh.DataValueField = "ID";
        DropDownListBakhsh.DataTextField = "Name";
        DropDownListBakhsh.DataBind();
    }
    protected void DropDownListBakhsh_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownListDehestan.DataSource = DataAccess.TblDehestan.FetchByParameter(DataAccess.TblDehestan.Columns.BakhshId, SubSonic.Comparison.Equals, DropDownListBakhsh.SelectedItem.Value);
        DropDownListDehestan.DataValueField = "ID";
        DropDownListDehestan.DataTextField = "Name";
        DropDownListDehestan.DataBind();
    }
    protected void DropDownListDehestan_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}